<template>
    <div>
        <el-card>
            <el-card>
                <el-table
                        :data="orgList"
                        style="width: 100%;margin-bottom: 20px;"
                        border>
                    <el-table-column
                            prop="id"
                            label="机构ID"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="org_name"
                            label="机构名称"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="org_code"
                            label="机构代码"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="parent"
                            label="父机构">
                    </el-table-column>
                </el-table>
            </el-card>
        </el-card>
    </div>
</template>

<script>
    import {org_list} from "../../../request/api";

    export default {
        name: "index",
        data() {
            return {
                orgList: [],
                org_listCopy:[]
            }
        },
        props:{
            pageSize: {
                type: Number
            },
            currentPage: {
                type: Number
            }
        },
        methods: {
            handleClick(row) {
                console.log(row);
            },
            getOrgList() {
                org_list().then(res => {
                    console.log(res);
                    this.orgList = res;
                    this.org_listCopy = this.orgList;
                    this.$emit('total',res.length);
                })
            },
        },
        watch: {
            pageSize() {
                this.orgList = this.org_listCopy;
                console.log('传递参数', this.currentPage, this.pageSize);
                this.orgList = this.orgList.slice((this.currentPage - 1)*this.pageSize,this.currentPage*this.pageSize);
            },
            currentPage() {
                this.orgList = this.org_listCopy;
                console.log('传递参数', this.currentPage, this.pageSize)
                this.orgList = this.orgList.slice((this.currentPage - 1)*this.pageSize,this.currentPage*this.pageSize);
                console.log(this.orgList)
            }
        },
        created() {
            this.getOrgList();
            console.log('分页参数',this.currentPage,this.pageSize)
        }
    }
</script>

<style scoped>

</style>
